#define _CRT_SECURE_NO_WARNINGS 
#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> prices(n);

    for (int i = 0; i < n; i++)
    {
        cin >> prices[i];
    }

    int min = prices[0];
    int max = 0;
    for (int i = 0; i < n; i++) {
        min = fmin(prices[i], min);
        max = fmax(max, prices[i] - min);
    }
    cout << max << endl;

    return 0;
}